{% extends 'admin/layout/base.html.twig' %}

{% block content %}

<div class="main">
    <!-- MAIN CONTENT -->
    <div class="main-content">
        <div class="container-fluid">
            <!-- OVERVIEW -->
             <div class="row">
                {% for entity in pagination %}   
                    <div class="col-md-3">
                        <div class="panel">
                            <div class="metric">
                                {% if entity.picurl %}
                                    <div class="coverimage icon"><img src="{{entity.picurl}}" /></div>
                                {% else %}
                                    <span class="icon"><i class="fa fa-eye"></i></span>
                                {% endif %}
                                <p>
                                    <span class="number">{{entity.name}}</span>
                                    <span class="title">{{entity.category.name}}</span>
                                    {% if entity.active==1 %}
                                        <span class="label label-primary">Active</span>
                                    {% else %}
                                        <span class="label label-default">Inactive</span>
                                    {% endif %}
                                    
                                </p>
                            </div>
                            <p class="demo-button">
                                <a href="{{path('showPage',{id:entity.id})}}" target="_blank" class="btn btn-success"><i class="fa fa-check-circle"></i> View</a>
                                <a href="{{path("admin_page_create",{id:entity.id})}}"class="btn btn-warning edit-page" data-value="{{entity.id}}"><i class="fa fa-warning"></i> Edit</a>
                                <button style="margin-bottom:0px;" type="button" class="btn btn-danger delete-page" data-value="{{entity.id}}"><i class="fa fa-trash-o"></i> Delete</button>
							</p>
                        </div>
                    </div>   
                                                       
                {% endfor %}
                
            </div>
            <div class="row pagination-outer">
                {{ knp_pagination_render(pagination) }}  
            </div>
        </div>
    </div>
</div>    
{% endblock %}
{% block jscript %}
    <script type="text/javascript">
        $("body").on('click','.delete-page',function(){
            var _this = $(this);
            layer.confirm('Delete anyway?', {
                title:"Note",
                btn: ['Sure','Cancel'] //按钮
                }, function(){
                    var index = layer.load(1, {
                    shade: [0.1,'#fff'] 
                    });
                    var id = _this.data('value');console.log(id);
                    $.post("{{path('deletePage')}}",{id:id},function(result){
                        console.log(result);
                       if(result['errno']==0){
                            layer.close(index);
                            layer.msg('Success !', {icon: 1});
                            _this.parents('.col-md-3').remove();
                        } else {
                            layer.close(index);
                        layer.msg('Something Wrong! Please try later.', {icon: 0});
                        }
                    });
                });
        })
    </script>
{% endblock %}

